﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElectronicCommerce.Framework.Diagnostics;
using ElectronicCommerce.Framework.ServiceModel.Configuration;
using ElectronicCommerce.Framework.ServiceModel.WCF;

namespace ElectronicCommerce.Framework.ServiceModel
{
    /// <summary>
    /// 
    /// </summary>
    public class ServiceBrokerFactory
    {
        private ServiceBrokerFactory()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IServiceBroker Create(Type serviceType, string serviceName)
        {
            Check.Argument.IsNotNull("serviceType", serviceType);
            Check.Argument.IsNotNull("serviceName", serviceName);

            ServiceElement serviceElement
                = ServiceModelConfigHelper.ServiceConfig.GetMixServiceElement(serviceType, serviceName);

            return Create(serviceElement.CallType);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public static IServiceBroker Create(Type serviceType)
        {
            Check.Argument.IsNotNull("serviceType", serviceType);

            return Create(serviceType, serviceType.Name);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="callType"></param>
        /// <returns></returns>
        public static IServiceBroker Create(ServiceCallType callType)
        {
            if (callType == ServiceCallType.Assembly)
                return AssemblyServiceBroker.Instance;
            else
                return WCFServiceBroker.Instance;
        }
    }
}
